const request = require("./http.js");

//添加名片信息
var addcard = function (data, callback) {
  request({
    url: "/mall/businesscard/insert",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//修改信息
var updatecard = function (data, callback) {
  request({
    url: "/mall/businesscard/updateAll",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//查询默认名片
var getDefaultCard = function (id, callback) {
    request({
      url: "/mall/businesscard/selectIsDefault?customerId=" + id,
      method: "get",
      success: function (res) {
        callback(res);
      },
      fail: function (err) {
        console.log(err);
        wx.showToast({
          title: err.errMsg,
          icon: "none",
          duration: 2000,
        });
      },
    });
  };
//查询浏览量
var getCount = function (id, callback) {
  request({
    url: "/mall/customervisit/selectCount?cardId=" + id,
    method: "get",
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//设为默认
var settingCard = function (data, callback) {
  request({
    url: "/mall/businesscard/updateIsDefault?cardId=" +data.cardId +'&customerId='+data.customerId,
    method: "get",
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//名片列表
var cardList = function (data, callback) {
  request({
    url: "/mall/businesscard/selectAll?customerId="+ data,
    method: "get",
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//删除名片
var deleCard = function (data, callback) {
  request({
    url: "/mall/businesscard/updateIsDelete?cardId="+ data,
    method: "get",
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
//单个查询
var getCardDetail = function (id, callback) {
    request({
      url: "/mall/businesscard/selectOne?cardId=" + id,
      method: "get",
      success: function (res) {
        callback(res);
      },
      fail: function (err) {
        console.log(err);
        wx.showToast({
          title: err.errMsg,
          icon: "none",
          duration: 2000,
        });
      },
    });
  };
//插入浏览信息
var insertcard = function (data, callback) {
  request({
    url: "/mall/customervisit/insert",
    method: "post",
    data: data,
    success: function (res) {
      callback(res);
    },
    fail: function (err) {
      console.log(err);
      wx.showToast({
        title: err.errMsg,
        icon: "none",
        duration: 2000,
      });
    },
  });
};
module.exports = {
  addcard:addcard,//添加名片信息
  updatecard:updatecard,//修改信息
  getDefaultCard:getDefaultCard,//查询默认名片
  getCount:getCount,//查询浏览量
  settingCard:settingCard,//设为默认名片
  cardList:cardList,//名片列表
  deleCard:deleCard,//删除名片
  getCardDetail:getCardDetail,//单个查询
  insertcard:insertcard,//插入浏览信息
}